﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tulde.MP3tunes;

namespace WP7.LockerPlayer.ViewModels
{
    public class TrackViewModel
    {

        public string TrackId { get; set; }
        public string TrackTitle { get; set; }
        public string TrackNumber { get; set; }
        public long? TrackLength { get; set; }
        public string TrackFileName { get; set; }
        public long? TrackFileSize { get; set; }
        public string DownloadUrl { get; set; }


        public string AlbumId { get; set; }
        public string AlbumTitle { get; set; }
        public string AlbumYear { get; set; }
        public string ArtistName { get; set; }
        public string PlayURL { get; set; }
        public string PlaymixURL { get; set; }
        public string TrackFileKey { get; set; }
        private string _url;
        public string AlbumArtUrl
        {
            get
            {
                if (_url == null)
                {
                    this._url = this.CreateAlbumUrl(AlbumArtSizeOptions.small);
                }
                return _url;
            }
            set
            {
                _url = value;
            }
         
      
        
        }
        private string CreateAlbumUrl(AlbumArtSizeOptions size)
        {
            AlbumArtService service = new AlbumArtService();
            Uri url = service.CreateServiceEndpoint(LockerDataOperations.albumartget, new AlbumArtServiceParameters
            {
                AlbumServiceKey = this.AlbumId,
                Size = size
            });
            return url.AbsoluteUri;
        }

        public double GetTimeInMinutes()
        {
            double d = this.TrackLength.HasValue ? this.TrackLength.Value : 0;
            double divisor = 60000;
            if (d > 0)
            {
                return d / divisor;
            }
            else
            {
                return 0;
            }
        }
        public string GetUrlFix()
        {
            return this.PlayURL + "&ext=.mp3";
        }
        public TrackViewModel()
        {

        }
    }
}
